package com.example.chapter05.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.example.chapter05.R;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link BlankFragment2#newInstance} factory method to
 * create an instance of this fragment.
 */
public class BlankFragment2 extends Fragment implements View.OnClickListener {
    private View root;
    private TextView textView;

    private Button button;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        // inflate 解析器
        if (root == null)
            root = inflater.inflate(R.layout.fragment_blank1, container, false);
        textView = root.findViewById(R.id.tv_fragment);
        button = root.findViewById(R.id.btn_fragment);
        button.setOnClickListener(this);
        return root;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onClick(View view) {
        if (view.getId()==R.id.btn_fragment){
            textView.setText("I am fine, thank you.");
        }
    }
}